import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'package:flutter_app/model/city_data.dart';
import 'package:http/http.dart' as http;

const CITY_DATA_URL = 'http://www.mxnzp.com/api/address/list';
/// 获取城市大接口
class CityDataDao {
  static Future<CityData> fetch() async {
    final response = await http.get(CITY_DATA_URL);
    if (response.statusCode == 200) {
      Utf8Decoder utf8decoder = Utf8Decoder(); //fix 中文乱码
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return CityData.fromJson(result);
    } else {
      throw Exception('Failed to load Data');
    }
  }
}
